package arrAndstr;

public class T6 {

    public static void main(String[] args) {
        String s = "A";
        int numRows = 1;

        System.out.println(convert(s, numRows));
    }

    public static String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }
        int len = s.length();
        int flag = 1;   // 1向下
        int rowIndex = 0;
        int columnIndex = 0;
        char[][] newArray = new char[numRows][1000];
        fillZero(newArray);

        for(int i=0; i<len; i++) {
            char ch = s.charAt(i);
            newArray[rowIndex][columnIndex] = ch;
            if((i % (2*numRows-2)) >= numRows-1 ) {
                columnIndex++;
            }
            if(rowIndex == 0)   flag = 1;
            if(rowIndex == numRows-1)   flag = -1;
            rowIndex = flag == 1 ? rowIndex+1 : rowIndex-1;
        }

        StringBuffer sb = new StringBuffer("");
        for(int i=0; i<numRows; i++) {
            for(int j=0; j<1000; j++) {
                if(newArray[i][j] != '0') {
                    sb.append(newArray[i][j]);
                }
            }
        }

        return sb.toString();
    }

    public static void fillZero(char[][] array) {
        for(int i=0; i<array.length; i++) {
            for(int j=0; j<array[0].length; j++) {
                array[i][j] = '0';
            }
        }
    }
}
